/*
 *  Copyright (C) 2010 Glauco
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.balisunrise.swing.transaction.panel;

import java.util.ArrayList;
import java.util.List;
import javax.swing.JComponent;
import javax.swing.JPanel;
import org.balisunrise.builder.BuilderException;
import org.balisunrise.swing.builder.LayoutBuilder;

/**
 *
 * @author Glauco
 */
public class TransactionPanel extends JPanel{
    
    private JPanel actionPanel;
    private JPanel editorPanel;
    private JPanel searchPanel;
    private LayoutBuilder layoutBuilder;
    private List<JComponent> list;

    public TransactionPanel(JPanel actionPanel, JPanel editorPanel,
            JPanel searchPanel, LayoutBuilder layoutBuilder) {

        this.actionPanel = actionPanel;
        this.editorPanel = editorPanel;
        this.searchPanel = searchPanel;
        this.layoutBuilder = layoutBuilder;
        this.list = new ArrayList<JComponent>(2);

    }

    public JPanel getActionPanel() {
        return actionPanel;
    }

    public void setActionPanel(JPanel actionPanel) {
        this.actionPanel = actionPanel;
    }

    public JPanel getEditorPanel() {
        return editorPanel;
    }

    public void setEditorPanel(JPanel editorPanel) {
        this.editorPanel = editorPanel;
    }

    public LayoutBuilder getLayoutBuilder() {
        return layoutBuilder;
    }

    public void setLayoutBuilder(LayoutBuilder layoutBuilder) {
        this.layoutBuilder = layoutBuilder;
    }

    public JPanel getSearchPanel() {
        return searchPanel;
    }

    public void setSearchPanel(JPanel searchPanel) {
        this.searchPanel = searchPanel;
    }

    public void showEditor(){

        list.clear();
        list.add(actionPanel);
        list.add(editorPanel);

        try{
            layoutBuilder.create(this, list);
        }catch(BuilderException ex){
            System.out.println(
                    "Erro em TransactionPanel ao disparar showEditor.\n"+
                    ex.getMessage());
        }

    }

    public void showSearch(){

        list.clear();
        list.add(actionPanel);
        list.add(searchPanel);

        try{
            layoutBuilder.create(this, list);
        }catch(BuilderException ex){
            System.out.println(
                    "Erro em TransactionPanel ao disparar showSearch.\n"+
                    ex.getMessage());
        }
    }
}
